// house_pkg/pages/room/index.ts
Page({
  /**
   * 页面的初始数据
   */
  data: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad({ point, building }) {
    this.fakeData(point, building)
  },
  // 1. 造数据
  fakeData(point, building) {
    // 1.1 随机产生几个房间
    const size = Math.floor(Math.random() * 4) + 5 // 5-8
    // 1.2 产生房间号
    const rooms = []
    for (let i = 0; i < size; i++) {
      // 1.2.1 随机产生楼层 (1-20)
      const floor = Math.floor(Math.random() * 20) + 1
      // 1.2.3 随机产生房间号(1-4)
      const no = Math.floor(Math.random() * 4) + 1
      // 1.2.4 组合房间号
      const room = [floor, '0', no].join('')
      // 1.2.6 去重
      if (rooms.includes(room)) continue
      // 1.2.5 把产生的房间放入数组
      rooms.push(room)
    }
    // 1.3 更新数据
    this.setData({
      rooms,
      point,
      building,
    })
  },
  // 2. 去添加房屋页面
  goForm(ev) {
    const { point, building } = this.data
    wx.navigateTo({
      url: `/house_pkg/pages/form/index?point=${point}&building=${building}&room=${ev.mark.room}`,
    })
  },
})
